import Vue from 'vue'
import axios from 'axios'
import VueAxios from 'vue-axios'
import router from './router'
import store from './store'
import App from './App.vue'
import './../public/iconfont/iconfont.css'
import VueLazyload from 'vue-lazyload'
import VueCookie from 'vue-cookie'
import './plugins/element'
import 'element-ui/lib/theme-chalk/index.css'
// import env from './env'

// 设置基础值 根据前端跨域方式做调整 接口代理
axios.defaults.baseURL = '/api'
// axios.defaults.baseURL = env.baseURL
axios.defaults.timeout = 8000
// 拦截器 响应拦截 错误拦截
axios.interceptors.response.use(function (response) {
  let res = response.data
  let path = location.hash
  if (res.status === 0) {
    return res.data
  } else if (res.status === 10) {
    // 未登录 这里面吗不可以用routerlink
    if (path !== '#/index') {
      window.location.href = '/#/login'
    }
    return Promise.reject(res) // 相当于报错 不进then 进 catch
  } else {
    this.$message.error(res.msg)
    return Promise.reject(res)
  }
})

// 注册 挂载
Vue.use(VueAxios, axios)
Vue.use(VueCookie)
Vue.use(VueLazyload, {
  loading: '/imgs/loading-svg/loading-bars.svg'
})
Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
